﻿using ConfExpert.Forms.Base;
using DevTeam;

using System;
using System.Drawing;

namespace ConfExpert.Forms.Sistem
{
    public partial class Vendor : XForm
    {
        public Vendor()
        {
            InitializeComponent();
        }

        private void Vendor_Load(object sender, EventArgs e)
        {       
            gvVendor.Init("GetVendor", false);
            gvVendor.ClearColumnEdit("CariId","VendorId");            
            gvVendor.MakeColumnInvisible("VendorId");
            gvVendor.MakeColumnsReadOnly("CariId");
            gvVendor.YanYanaGetirSoluna("Unvan", "Abbr", "OriginId");
            gvVendor.Columns["Deleted"].VisibleIndex = 100;
            btnKaydet.ItemClick += btnKaydet_ItemClick;            
            chkShowOnly.CheckedChanged += btnShowOnly_CheckedChanged;

            gvVendor.AddSummary();
            gvVendor.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;
            gvVendor.RowStyle += gvVendor_RowStyle;
            gvVendor.BestFitColumns();            
        }

        void btnShowOnly_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvVendor.RefreshDataSource("GetVendor", chkShowOnly.Checked);
            gvVendor.BestFitColumns();
        }

        void gvVendor_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            if (e.RowHandle > -1)
                if (gvVendor.GetRowCellValue(e.RowHandle, "VendorId").ToInt() > 0)
                            e.Appearance.Font = new Font(e.Appearance.Font, FontStyle.Bold);
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvVendor.EndEditing();
            string name = gvVendor.GetFocusedDataRow()["Name"].ToStr();
            string str = gvVendor.SerializeChanges();
            ExecuteNonQuery("UpdVendor", str);
            gvVendor.RefreshDataSource("GetVendor", chkShowOnly.Checked);
            gvVendor.FocusedRowHandle = gvVendor.LocateByDisplayText(0, gvVendor.Columns["Name"], name);
            gvVendor.MakeRowVisible(gvVendor.FocusedRowHandle);
            gvVendor.BestFitColumns();
        }
    }
}
